"""
Case Type   : bugfix
Case Name   : 用户自定义变量赋值为binary类型
Create At   : 2025/6/12
Owner       : liu-tong-8848
Description :
    1、设置b_compatibility_mode为true,b_format_behavior_compat_options为enable_set_variables
    2、向用户自定义变量赋值binary类型
Expect      :
    1、成功
    2、成功
History     :
"""

import os
import unittest

from yat.test import Node
from yat.test import macro

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger


class BugFix(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.common = Common()
        self.sh_primary = CommonSH('PrimaryDbBmode')
        self.user_node = Node('PrimaryDbBmode')
        self.constant = Constant()

    def test_dolphin(self):
        self.log.info(f'----{os.path.basename(__file__)} start----')
        text = '----step1:设置b_compatibility_mode为true,b_format_behavior_compat_options为enable_set_variables；' \
               + 'expect:成功----'
        self.log.info(text)
        sql_cmd = "set dolphin.b_compatibility_mode = true; set b_format_behavior_compat_options = enable_set_variables; " \
                  + "set @S = cast('test' as binary); select @S;"
        self.log.info(sql_cmd)
        sql_res = self.sh_primary.execut_db_sql(sql_cmd)
        self.log.info(sql_res)
        self.assertIn(self.constant.SET_SUCCESS_MSG, sql_res, '执行失败' + text)

        text = '----step2:打开enable_opfusion，打开enable_partition_opfusion；expect:成功----'
        self.log.info(text)
        self.assertIn('@s', sql_res, '执行失败' + text)
        self.assertIn('(1 row)', sql_res, '执行失败' + text)

    def tearDown(self):
        self.log.info(f'----{os.path.basename(__file__)} end-----')
